package exercise;

import expression.Expression;

/**
 * 习题类 - 实验内容2
 * 封装题目和用户答案
 */
public class Exercise {
    private Expression expression;
    private int userAnswer;
    private boolean answered;
    
    public Exercise(Expression expression) {
        this.expression = expression;
        this.answered = false;
    }
    
    public void setUserAnswer(int answer) {
        this.userAnswer = answer;
        this.answered = true;
    }
    
    public boolean isCorrect() {
        return answered && userAnswer == expression.calculate();
    }
    
    public int getScore() {
        return isCorrect() ? 1 : 0;
    }
    
    public String getQuestion() {
        return expression.getExpression() ;
    }
    
    public String getQuestionWithAnswer() {
        return expression.toString();
    }
    
    public Expression getExpression() {
        return expression;
    }
}